package com.happystudy.serviceImpl;

import com.happpystudy.model.grade.Grade;
import com.happpystudy.service.GradeService;
import com.happystudy.mapper.GradeMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GradeServiceImpl implements GradeService {

    @Resource
    GradeMapper gradeMapper;

    @Override
    public Grade queryGradeByKey(Grade grade){
        return gradeMapper.selectGradeByKey(grade);
    }
    @Transactional
    @Override
    public int insertGrade(Grade grade){
        return  gradeMapper.insertSelective(grade);
    }

    @Override
    public int doUpdateGrade(Grade record){
        int result = 0;
        Grade grade = this.queryGradeByKey(record);
        if (grade!=null){
            result = this.UpdateGrade(record);
        }else {
            result = this.insertGrade(record);
        }
        return result;
    }
    @Transactional
    @Override
    public int UpdateGrade(Grade grade) {
        return gradeMapper.undateGrade(grade);
    }

    @Override
    public List<Grade> getAllGradeByUserId(Integer userId) {
        return gradeMapper.selectAllByUserId(userId);
    }
}
